package com.dubbo.snail.service;

import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlBlockHandler;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description TODO
 * @Author xueguoping
 * @Date 2021/5/11 10:48
 */
@Service
public class CustomUrlBlockHandler implements UrlBlockHandler {
	public void blocked(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, BlockException e) throws IOException {
		httpServletResponse.setHeader("Content-Type","application/json;charset=UTF-8");
		String message="{\"code\":999,\"msg\":\"访问人数过多\"}";
		httpServletResponse.getWriter().write(message);
	}
}
